import Vue from 'vue'
import VueRouter from 'vue-router'
import Tabbar from '../components/tabbar.vue'
Vue.use(VueRouter)
const routes = [
  {
    path: '/',
    name: 'Tabbar',
    redirect: '/home',
    component: Tabbar,
    children: [
      {
        path: '/home',
        name: 'Home',
        component: () => import(/* webpackChunkName: "home" */ '../views/home/index.vue'),
        meta: {
          title: '首页'
        }
      },
      {
        path: 'shopCar',
        name: 'ShopCar',
        component: () => import(/* webpackChunkName: "shopCar" */ '../views/shopCar/index.vue'),
        meta: {
          title: '购物车'
        }
      },
      {
        path: 'order',
        name: 'Order',
        component: () => import(/* webpackChunkName: "order" */ '../views/order/index.vue'),
        meta: {
          title: '订单'
        }
      },
      {
        path: 'mine',
        name: 'Mine',
        component: () => import(/* webpackChunkName: "mine" */ '../views/mine/index.vue'),
        meta: {
          title: '我的'
        }
      }
    ]
  },
  {
    path: '/home/detail',
    name: 'HomeDetail',
    component: () => import('../views/home/homeDetail.vue'),
    meta: {
      title: '首页详情'
    }
  }
]
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
const routerPushProto = VueRouter.prototype.push
const routerBackProto = VueRouter.prototype.go
VueRouter.prototype.push = function (location) {
  Vue.prototype.$eventBus.$emit('onPushEvent')
  routerPushProto.call(this, location)
}
VueRouter.prototype.go = function (location) {
  Vue.prototype.$eventBus.$emit('onBackEvent')
  routerBackProto.call(this, location)
}
router.beforeEach((to, from, next) => {
  next()
})
export default router
